package com.yyplatform.admin.platform.init.data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.yyplatform.admin.platform.log.controller.SysErrorLogController;
import com.yyplatform.admin.platform.log.controller.SysOperationLogController;
import com.yyplatform.admin.platform.role.controller.SysCaptchaLogController;
import com.yyplatform.admin.platform.role.controller.SysLoginHisController;
import com.yyplatform.admin.platform.role.model.entity.SysMenuEntity;
import com.yyplatform.admin.platform.role.model.enums.MenuTypeEnum;
import com.yyplatform.admin.platform.role.repository.SysMenuRepository;
import com.yyplatform.admin.platform.role.service.SysMenuService;

/**
 * @author sleepforests@163.com
 * <p>
 * Created on 2024/11/16 20:42
 */

public class InitMenuData3Log {

    private SysMenuRepository sysMenuRepository;

    private SysMenuService sysMenuService;


    public InitMenuData3Log(SysMenuRepository sysMenuRepository, SysMenuService sysMenuService) {
        this.sysMenuRepository = sysMenuRepository;
        this.sysMenuService = sysMenuService;
    }


    public void init() {
        String name = "日志管理";
        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(true);
        menu.setComponent("Layout");
        menu.setEnabled(true);
        menu.setIcon("table");
        menu.setKeepAlive(true);
        menu.setName(name);
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("");
        menu.setPid(0L);
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("");
        menu.setRoutePath("/log");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_FOLDER.getValue());

        sysMenuRepository.save(menu);

        test_init_系统工具_操作日志(menu);
        test_init_系统工具_登录日志(menu);
        test_init_系统工具_错误日志(menu);
        test_init_系统工具_验证码管理(menu);


    }

    public void test_init_系统工具_操作日志(SysMenuEntity rootMenu) {

        long id = 0;


        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/operationLog/index");
        menu.setEnabled(true);
        menu.setIcon("table");
        menu.setKeepAlive(true);
        menu.setName("操作日志");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:operationLog:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("OperationLog");
        menu.setRoutePath("platform/operationLog/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        id = menu.getId();


        List<String> list2 = new ArrayList<>();
        list2.add(SysOperationLogController.class.getName());
        sysMenuService.saveBatchByControllerName(id, list2);

    }


    public void test_init_系统工具_登录日志(SysMenuEntity rootMenu) {

        long id = 0;


        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/loginHis/index");
        menu.setEnabled(true);
        menu.setIcon("el-icon-Calendar");
        menu.setKeepAlive(true);
        menu.setName("登录日志");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:loginHis:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("LoginHis");
        menu.setRoutePath("platform/loginHis/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        id = menu.getId();


        List<String> list2 = new ArrayList<>();
        list2.add(SysLoginHisController.class.getName());
        sysMenuService.saveBatchByControllerName(id, list2);

    }

    public void test_init_系统工具_错误日志(SysMenuEntity rootMenu) {

        long id = 0;


        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/errorLog/index");
        menu.setEnabled(true);
        menu.setIcon("el-icon-WarnTriangleFilled");
        menu.setKeepAlive(true);
        menu.setName("错误日志");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:errorLog:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("ErrorLog");
        menu.setRoutePath("platform/errorLog/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        id = menu.getId();


        List<String> list2 = new ArrayList<>();
        list2.add(SysErrorLogController.class.getName());
        sysMenuService.saveBatchByControllerName(id, list2);

    }

    public void test_init_系统工具_验证码管理(SysMenuEntity rootMenu) {


        long id = 0;


        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/captchaLog/index");
        menu.setEnabled(true);
        menu.setIcon("el-icon-Iphone");
        menu.setKeepAlive(true);
        menu.setName("验证码日志");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:captchaLog:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("CaptchaLog");
        menu.setRoutePath("platform/captchaLog/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        id = menu.getId();


        List<String> list2 = new ArrayList<>();
        list2.add(SysCaptchaLogController.class.getName());
        sysMenuService.saveBatchByControllerName(id, list2);

    }

}



